package com.zhoudy.mpstudy;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface BlogMapper extends BaseMapper<Blog> {

    @SelectProvider(type = BlogSqlProvider.class, method = "getSql")
    @Results(value = {
            @Result(id = true, property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
            @Result(property = "title", column = "title", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "date", column = "date", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "content", column = "content", javaType = String.class, jdbcType = JdbcType.VARCHAR),
    })
    Blog getBlog(@Param("id") int id);

    @SelectProvider(type = BlogSqlProvider.class, method = "getAllSql")
    @Results(value = {
            @Result(id = true, property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
            @Result(property = "title", column = "title", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "date", column = "date", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "content", column = "content", javaType = String.class, jdbcType = JdbcType.VARCHAR),
    })
    List<Blog> getAllBlog();

    @SelectProvider(type = BlogSqlProvider.class, method = "getSqlByTitle")
    @Results(value = {
            @Result(id = true, property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
            @Result(property = "title", column = "title", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "date", column = "date", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "content", column = "content", javaType = String.class, jdbcType = JdbcType.VARCHAR),
    })
    List<Blog> getBlogByTitle(@Param("title") String title);

    @InsertProvider(type = BlogSqlProvider.class, method = "insertSql")
    void insertBlog(Blog blog);

    @UpdateProvider(type = BlogSqlProvider.class, method = "updateSql")
     void updateBlog(Blog blog);

    @DeleteProvider(type = BlogSqlProvider.class, method = "deleteSql")
    void deleteBlog(int ids);


}